import * as Apis from "../../apis/Api";
import { observable, action } from 'mobx';


class SynergyStore {

    @observable tabsInfo =[];
    @observable tabKey = "";
    @observable initInfo = {isUse:false,isShow:false,refId:-1,title:"合同信息"};
    @observable Card = {};
    
    @observable dialog = {visible:false};
    @observable params = {};

    @action 
    clearStore = () => {
        this.tabsInfo = [];
        this.tabKey = "";
        this.initInfo = {isUse:false,isShow:false,refId:-1,title:"合同信息"};
        this.Card = new weaCube.common.CardStore();
        this.dialog = {visible:false};
        this.params = {};
    }

    @action 
    initTabs = (refId=-1,tabKey)=>{
        const requestParams = {contractId:refId};
        const that = this;
        Apis.getCardTabs(requestParams).then(data => {
            that.tabsInfo = data.datas;
            data.datas&&data.datas.map(params=>{
                if(("planPay"==tabKey||"planIncom"==tabKey)&&"plan"==params.shortname){
                    that.tabKey = params.sequence;return;
                }else if(("pay"==tabKey||"incom"==tabKey)&&"pay"==params.shortname){
                    that.tabKey = params.sequence;return;
                }else if("ticket"==tabKey&&"ticket"==params.shortname){
                    that.tabKey = params.sequence;return;
                }else if("risk"==tabKey&&"risk"==params.shortname){
                    that.tabKey = params.sequence;return;
                }else if("base"==params.shortname){
                    that.tabKey = params.sequence;return;
                }
            })
		});
    }

    @action
    initSynergy = (isUse=false,isShow=false,custom,refId,title="合同信息",tabKey="1") => {
        this.initInfo = {isUse:isUse,isShow:isShow,custom:custom,refId:refId,title:title};
        this.Card = new weaCube.common.CardStore();
    }

    @action
    isUseSynergy = (isUse)=>{
        this.initInfo.isUse = isUse;
    }

    @action
    isShowSynergy = (isShow)=>{
        this.initInfo.isShow = isShow;
    }

    @action
    changeTab = (tabKey)=>{
        this.tabKey = tabKey;
    }

    @action
    initCard = (params,from)=>{
        this.params = params;
        this.dialog.visible = true;
        this.dialog.from = from;
        this.Card = new weaCube.common.CardStore();
        this.Card.init(params);
        this.Card.modeExcel.containerWidth = 1050;
    }

    @action
    clearDialog = (params)=>{
        this.dialog.visible = false;
    }

    @action
    reloadCard = ()=>{
        this.Card.init(this.params);
        this.Card.modeExcel.containerWidth = 1050;
    }
    
}

export default SynergyStore;